package com.ckm.provider;

import com.ckm.creator.DefaultMongoSourceCreator;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
import org.springframework.data.mongodb.MongoDatabaseFactory;

import java.util.HashMap;
import java.util.Map;

@RequiredArgsConstructor
public abstract class AbstractMongoSourceProvider implements DynamicMongoSourceProvider{

    private final DefaultMongoSourceCreator defaultMongoSourceCreator;

    protected Map<String , MongoDatabaseFactory> createMongoSourceMap(Map<String, MongoProperties> mongoPropertiesMap){
        HashMap<String, MongoDatabaseFactory> factoryHashMap = new HashMap<>();
        for (Map.Entry<String, MongoProperties> entry : mongoPropertiesMap.entrySet()) {
            factoryHashMap.put(entry.getKey(), defaultMongoSourceCreator.createMongoDataSource(entry.getValue()));
        }
        return factoryHashMap;
    }
}
